home *** CD-ROM | disk | FTP | other *** search
/ Developer Source 18 / Developer Source Volume 18 (I-MODE Publications, Inc.)(2000).iso / visua / feb98 / swanf105.gif < prev    next >
Graphics Interchange Format  |  1998-06-08  |  41KB  |  601x677  |  4-bit (4 colors)
Labels: text | screenshot | font | number | black and white | parallel | document
OCR: Method Description void addNotify This method attaches a native operating-system peer object to the menu, and applications should have little, if any, reason to call addNotify. void remove Notify This method detaches the menu from its peer. As with the preceding method, you should have little, If any, reason to call this method. boolean istearOff Returns true if this menu can be torn away from its mother menu bar, In theory, such a menu con remain on screen and possibly be moved as though it were a separate window. int countifems This returns the number of Menulfem objects held by the Menu container. (An item, remember, can also be an object of the Menu class, which extends from Menultem:) Menultem gefltem(inf index) Returnis the Menuitem object, which could olso be an object of the Menu class, having the specified index. The first item in a menu has the index zero. Menultom add(Menulfem mi) Adds a new Menultem object to the bottom of the menu. For reasons that are not entirely clear (but possibly for debugging purposes), this method returns the same object passed as an argument. Menuitems are stored internally in a Menu object in a Vector container. Calling add uses Vector.addElement to add the new item to the menu, a fact that might be useful for debugging or in custom- menu creation software. It is interesting to note that calling add first removes the specified item from the menu so that no item can accidentally be added twice. This observation leads to a cute trick - calling add for any existing menu ifem moves it to the end of its popup menu. I've yet to find a practical use for this side effect, but perhaps you will. void add(String lobel) Adds a new Menultem object that is created using the specified String label. Use this form of add to create new Menultems if you don't want to save references to those items; Use the former method, as in the MenuDemo project, if you construct Menuitems separately and maintain references to them. You cannot use this string-argument form of add to create nested menus; to do that, con- struct the Menu object separately and pass it to the preceding add method. void addSeparator Adds a separator line to the bottom of the menu. This is handy for segmenting lengthy menus, but don't overdo it - too many separators are perhaps more confusing than too few. Alternatively, you may pass the string " . " (a single hyphen in quotes) to the add method to create a separator, which is all that addSeparator does. void remove(int index) Removes the Menuffem or Menu object of the specified index. This method would be highly useful in constructing dynamic menus that add now com- monds according to external circumstances except for a glaring omission in the Menu class - there is no corresponding insert method. Although you can remove a menu item from the middle of a menu, you can add new ones only at the end. (Tip: An extended class might manipulate the internal Vector object to insert menu items at random locations.) void remove(MenuComponent item) Removes the specified MenuComponent (which is probably an object of the Menu or Menultem closses). No error occurs if the component doesn't exist. Adding new menu items internally calls remove so that no item can accidentally be added twice to a menu, Figure 5: The public methods of the Menu class.